package org.jeecg.modules.simulator.factory;

import lombok.Getter;
import lombok.Setter;
import org.jeecg.modules.simulator.jsonot.PsgStationDistributionInfo;
import org.jeecg.modules.simulator.jsonot.PsgStationDistributionStType;
import org.jeecg.modules.simulator.jsonot.RouteStation;
import org.jeecg.modules.simulator.jsonot.TrainPsgDistributionApiInfo;
import org.jeecg.modules.simulator.model.line.station.station.Station;
import org.jeecg.modules.simulator.model.line.station.station.TransferStation;
import org.jeecg.modules.simulator.model.person.Person;
import org.jeecg.modules.simulator.model.person.path.PersonPath;
import org.jeecg.modules.simulator.model.person.path.PersonPathItem;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class LoadTimePeriodPersonHistory {

//    @Setter
//    Map<String, Station> stationMap = new HashMap<>();
//
//    @Setter
//    @Getter
//    Map<String, TransferStation> transferStationMap = new HashMap<>();
//
//    @Setter
//    @Getter
//    List<TrainPsgDistributionApiInfo> trainPsgDistribution;
//
//    @Setter
//    @Getter
//    List<PsgStationDistributionInfo> psgStationDistributionInfoList;
//    @Getter
//    // key: stationId,这个只是路径信息，不是人员信息
//    Map<String, List<PsgStationDistributionInfo>> stationPersonMap = new HashMap<>();
//
//
//    //乘车人员分布
//    @Getter
//    Map<String, List<Person>> personTrainMap = new HashMap<>();
//    /**
//     * @description: 从数据库查出车上人，然后生成路径信息，按车辆ID生成personMap
//     * @author: renzhg
//     * @date: 2024/10/8 9:21
//     **/
//    public void getTrainPsgStationDistribution(String dateStr) {
//
//
//
////        List<TrainPsgDistributionApiInfo> trainPsgDistribution = trainPsgDistributionMapper.getTrainPsgDistribution(dateStr);
//
//
//
//        Map<String, List<TrainPsgDistributionApiInfo>> trainIdMap = trainPsgDistribution.stream().collect(Collectors.groupingBy(TrainPsgDistributionApiInfo::getTrainNo));
//        for (Map.Entry<String, List<TrainPsgDistributionApiInfo>> entry : trainIdMap.entrySet()) {
//            List<Person> personList = new ArrayList<>();
//            for (int i = 0; i < entry.getValue().size(); i++) {
//                TrainPsgDistributionApiInfo trainPsgDistributionApiInfo = trainPsgDistribution.get(i);
//                String routeId = trainPsgDistributionApiInfo.getRouteId();
//                List<RouteStation> routeStations = t80RouteHisMap.get(routeId);
//                if (routeStations == null) {
//                    continue;
//                }
//                routeStations.sort((a, b) -> a.getStationSn().compareTo(b.getStationSn()));
//                List<PersonPathItem> personPathItemList = generatePersonPathIte mList(routeStations, routeId);
//                if (personPathItemList == null) {
//                    continue;
//                }
//                PersonPath personPath = new PersonPath(personPathItemList);
//                Person person = new Person(personPath);
//                personList.add(person);
//            }
//            personTrainMap.put(entry.getKey(), personList);
//        }
//    }
//
//
//    /**
//     * @description: 通过route生产personPathItemList
//     * @author: renzhg
//     * @date: 2024/10/8 10:15
//     **/
//    private List<PersonPathItem> generatePersonPathItemList(List<RouteStation> routeStations, String routeId) {
//        List<PersonPathItem> personPathItems = new ArrayList<>();
//        for (int n = 0; n < routeStations.size(); n++) {
//            PersonPathItem personPathItem = new PersonPathItem();
//            String stationId = routeStations.get(n).getStationId();
//            Station station = stationMap.get(stationId);
//            if (station == null) {
//                return null;
//            }
//            personPathItem.setStationId(stationId);
//            String name = stationMap.get(stationId).getName();
//            personPathItem.setStationName(name);
//            personPathItem.setIndex(n);
//            transferStationMap.forEach((k, v) -> {
//                if (v.isInTransferStation(stationId)) {
//                    personPathItem.setTransfer(true);
//                } else {
//                    personPathItem.setNeedTransfer(false);
//                }
//            });
//            if (routeStations.get(n).getTripDrctCd() == null) {
//                routeStations.get(n).setTripDrctCd("");
//            }
//            if (routeStations.get(n).getTripDrctCd().isEmpty()) {
//                personPathItem.setNeedTransfer(true);
//            } else {
//                personPathItem.setNeedTransfer(false);
//            }
//            personPathItem.setPathIndex(routeId);
//            personPathItems.add(personPathItem);
//        }
//        return personPathItems;
//    }
//
//
//    /**
//     * @description: 获取站点人员分布
//     * @author: renzhg
//     * @date: 2024/10/8 8:40
//     **/
//    public void getPsgStationDistribution(String dateStr) {
////        Timestamp timestamp = Timestamp.valueOf(dateStr + " 08:13:00");
//
////        Timestamp timestamp1 = Timestamp.valueOf(dateStr);
////        List<PsgStationDistributionInfo> psgStationDistributionInfoList = psgStationDistributionMapper.getPsgStationDistribution(dateStr);
//        List<PsgStationDistributionInfo> psgStationDistributionInfos = new ArrayList<>();
//        psgStationDistributionInfoList.forEach(e -> {
//
//            String key = e.getRouteId();
//            List<RouteStation> routeStations = t80RouteHisMap.get(key);
//            String routeSeqNum = e.getRouteSeqNum();
//            if (routeStations != null) {
//                if (routeStations.get(0).getStationSn().equals(routeSeqNum)) {
//                    String stationId = routeStations.get(0).getStationId();
//                    e.setStationId(stationId);
//                    e.setStationType(PsgStationDistributionStType.start);
//                    psgStationDistributionInfos.add(e);
//                }
//
//                if (routeStations.get(routeStations.size() - 1).getStationSn().equals(routeSeqNum)) {
//                    String stationId = routeStations.get(routeStations.size() - 1).getStationId();
//                    e.setStationId(stationId);
//
//                    e.setStationType(PsgStationDistributionStType.end);
//                    psgStationDistributionInfos.add(e);
//
//                }
//
//
//                for (int i = 0; i < routeStations.size(); i++) {
//                    if (routeSeqNum.equals(routeStations.get(i).getStationSn())) {
//                        if (routeStations.get(i).getTripDrctCd() == null) {
//                            routeStations.get(i).setTripDrctCd("");
//                        }
//                        if (routeStations.get(i).getTripDrctCd().isEmpty()) {
//                            String stationId = routeStations.get(i).getStationId();
//
//                            e.setStationId(stationId);
//                            e.setStationType(PsgStationDistributionStType.transfer);
//                            psgStationDistributionInfos.add(e);
//                        }
//
//                    }
//                }
//            }
//
//
//        });
//
//        stationPersonMap = psgStationDistributionInfos.stream().collect(Collectors.groupingBy(e -> e.getStationId()));
//
//
//    }


}
